home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d3 / rettig.arc / TRSOURCE.EXE / _TR_DOSC.C < prev    next >
C/C++ Source or Header  |  1990-10-22  |  3KB  |  126 lines

  1. /*********
  2. *   _TR_DOSC.C
  3. *
  4. *   by Ralph Davis and Tom Rettig
  5. *
  6. * Placed in the public domain by Tom Rettig Associates, 10/22/1990.
  7. *
  8. *   _tr_doscnf( <search string> )
  9. *
  10. *   called by files(), buffers(), country(), and lastdrive()
  11. *
  12. *   This function gets COMSPEC from the environment string,
  13. *   then loads CONFIG.SYS and looks for the requested parameter
  14. *
  15. *   May return either an integer if parameter begins with a
  16. *   digit, otherwise returns a char pointer.
  17. *
  18. *   modified by Leonard Zerman 02/04/88
  19. *   Second fix for last item in config.sys file with no trailing 
  20. *   blank or CR.
  21. *********/
  22.  
  23. #include "trlib.h"
  24.  
  25. _tr_doscnf(srch_strng)
  26. char *srch_strng;
  27. {
  28.    char *env = "COMSPEC";
  29.    char *p;
  30.    char boot_drive[16];
  31.    char *filename = "CONFIG.SYS";
  32.    char inline[80];
  33.  
  34.    int i, j;
  35.    int fd, mode = READONLY;
  36.    int filestat;
  37.    int retnum;
  38.    int srch_len;
  39.    int flag;
  40.  
  41.    /* Get COMSPEC */
  42.    if ((p = _tr_getenv(env)) == NULLLONG)
  43.       return(-1);
  44.  
  45.  
  46.    /* Extract drive letter and backslash for root directory */
  47.    for (i = 0; i < 3; i++)
  48.       boot_drive[i] = p[i];
  49.    boot_drive[i] = NULLC;
  50.  
  51.  
  52.    /* Concatenate filename to drive letter and backslash */
  53.    _tr_strcat(boot_drive, filename);
  54.  
  55.  
  56.    /* Open CONFIG.SYS */
  57.    if ((fd = _tr_open(boot_drive, mode)) == -1)
  58.       return(-1);
  59.  
  60.  
  61.    /* Read in each line of CONFIG.SYS */
  62.    i = 0;
  63.    flag= FALSE;
  64.    while (!flag)
  65.    {
  66.       filestat = (_tr_read(fd, &inline[i], 1) > 0);
  67.       if ((inline[i] != '\r') && (inline[i] != '\n') && filestat)
  68.       {
  69.          if (isalpha(inline[i]))
  70.             inline[i] &= 0xDF;     /* force input to uppercase */
  71.          
  72.          ++i;
  73.          continue;                 /* not end of line, get next character */
  74.       }
  75.       inline[i] = NULLC;           /* end of line, terminate with null */
  76.  
  77.  
  78.       /* Is this the parameter we're looking for? */
  79.       srch_len = _tr_strlen(srch_strng);
  80.       for (j = 0; j < srch_len; j++)
  81.          if (inline[j] != srch_strng[j])
  82.          {
  83.             i = 0;
  84.             break;               /* not equal, move on and loop back */
  85.          }
  86.       if (i > 0)                 /* yes, this is it */
  87.       {
  88.          i--;                    /* back up one from null */
  89.          break;                  /* leave the while loop */
  90.       }
  91.       if(!filestat)
  92.          break;
  93.    }
  94.  
  95.  
  96.    if ( /*filestat*/ i > 0 )           /* we have our parameter line */      
  97.    {
  98.       /* Back up over trailing white space, if any */
  99.       while ( inline[i]== ' ' || inline[i]=='\n' ||
  100.               inline[i]=='\t' || inline[i]=='\f' || inline[i]=='\r' )
  101.          i--;
  102.  
  103.       /* Back up over parameter to space, tab, or equal sign */
  104.       while ( inline[i]!=SPACEC && inline[i]!='\t' && inline[i]!='=' )
  105.          i--;
  106.  
  107.       /* Position the pointer to the parameter start */
  108.       ++i;
  109.  
  110.       /* Return parameter */
  111.       if ( isdigit(inline[i]) )
  112.          retnum = _tr_atoi(&inline[i]);     /* return integer */
  113.       else 
  114.          retnum = inline[i];                /* return char pointer */
  115.  
  116.       _tr_close(fd);
  117.       return(retnum);
  118.    }
  119.    else
  120.    {                   /* did not find the parameter in Config.sys */
  121.       _tr_close(fd);
  122.       return( ERROR );
  123.    }
  124. }
  125.  
  126.